<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page language="java" import="java.lang.*" %>
<%@ page import = "java.sql.SQLException" %>
<%@ page import = "com.seniorproject.aims.*" %>
<%@ page import = "java.util.List" %>
<%@page import="java.util.ArrayList"%>
<%@ page import = "java.util.Properties" %>
<%@ page import = "javax.servlet.ServletContext" %>
<%@ page import = "java.io.File" %>
<%@ page import = "java.io.InputStream" %>
<%@ page import = "java.sql.PreparedStatement" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Modified Course</title>
<link rel="stylesheet" type="text/css" href="css/stylev2.css" />

<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>

<style type="text/css">
	a {
      text-decoration:none;
   }
</style>

<script type="text/javascript">	

	
		function search_name(courseid) {
			if($('#namelist').find('option').length > 0) {
				
				$('#namelist').find('option').remove();
			}
			if(courseid.length>2) {
				
				/* AJAX */
				var xmlhttp;
				
				if(window.XMLHttpRequest) {
					// code for IE7+, Firefox, Chrome, Opera, Safari
					xmlhttp = new XMLHttpRequest();
				}
				else {
					// code for IE6, IE5
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
				
				xmlhttp.onreadystatechange = function() {
					if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
						
						
						var jsonObj = JSON.parse(xmlhttp.responseText);
						
						if(jsonObj.length == 0) {
							// no data
						}
						else{
							// show data
							for(i in jsonObj) {
								var text = jsonObj[i].courseId+" , "+jsonObj[i].courseNameEN+" , "+jsonObj[i].credit+" ( "+jsonObj[i].lecture+" "+jsonObj[i].lab+" "+jsonObj[i].selfLearn+" ) , "+jsonObj[i].details;
								var option = '<option value="'+text+'" >';
								$('#namelist').append(option);								
							}
							var result = document.getElementById("search_box").value;	
							
						}
					}
					
				}
				
				xmlhttp.open("POST", "curriculum_search_course_name.jsp?courseid="+courseid, true);
				xmlhttp.send();
				
			}	
		}
		
</script>


</head>
<body>
<%
//Get session
String strUser = String.valueOf(session.getAttribute("sUser"));
HttpSession htp_session = request.getSession();
		
if (htp_session == null || htp_session.getAttribute("sUser") == null) {
    // Forward the control to login.jsp if authentication fails or session expires
    request.getRequestDispatcher("/login.jsp").forward(request,
        response);
}

if("admin".equals(htp_session.getAttribute("sUser"))){%>
<script>alert("This user dont have PERMISSION to access this zone.");</script>
<meta HTTP-EQUIV="Refresh" CONTENT="0; URL=admin_home.jsp"> 	
<%}


//GET PERMISSION

		String name = String.valueOf(session.getAttribute("name"));
		String surname = String.valueOf(session.getAttribute("surname"));
		String role_name = String.valueOf(session.getAttribute("curriculum_role"));
		
		String department_id = String.valueOf(session.getAttribute("department_id"));
				
		System.out.println("name : " + name);///////////////////////////////
		System.out.println("department_id : " + department_id);/////////////////////////
		
		List<String> system_name = new ArrayList<String>();
		
		Permission permission = new Permission(strUser,name);
		permission.setCurriculumCreate(Boolean.valueOf(String.valueOf(session.getAttribute("curriculum_create"))));
		permission.setCurriculumDelete(Boolean.valueOf(String.valueOf(session.getAttribute("curriculum_delete"))));
		permission.setCurriculumRead(Boolean.valueOf(String.valueOf(session.getAttribute("curriculum_read"))));
		permission.setCurriculumUpdate(Boolean.valueOf(String.valueOf(session.getAttribute("curriculum_update"))));
		
		String permiss = "";
		if(permission.getCurriculumCreate()) {
			permiss = permiss + "Add";
		}
		if(permission.getCurriculumUpdate()) {
			if("".equals(permiss)) {
				permiss = permiss + "Edit";
			} else {
				permiss = permiss + " Edit";
			}
		}
		if(permission.getCurriculumRead()) {
			if("".equals(permiss)) {
				permiss = permiss + "Read";
			} else {
				permiss = permiss + " Read";
			}
		}
		if(permission.getCurriculumDelete()) {
			if("".equals(permiss)) {
				permiss = permiss + "Delete";
			} else {
				permiss = permiss + " Delete";
			}
		}
		
	///////////////////////////////////////////////////////////////////////////////////////////////////////////			
	//check permission
		if(!permission.getCurriculumCreate()){%>
			<script>alert("This user dont have PERMISSION to access this zone.");</script>
			<meta HTTP-EQUIV="Refresh" CONTENT="0; URL=curriculum_home.jsp"> 	
		<%}
	
//set Database Connection
	String hostProps = "";
	String usernameProps  = "";
	String passwordProps  = "";
	String databaseProps = "";

	try {
		//get current path
		ServletContext servletContext = request.getSession().getServletContext();
		
		InputStream input = servletContext.getResourceAsStream("/properties/connectDB.properties");
		Properties props = new Properties();
		
		props.load(input);

		hostProps  = props.getProperty("host");
		usernameProps  = props.getProperty("username");
		passwordProps  = props.getProperty("password");
		databaseProps = props.getProperty("database");
	} catch (Exception e) { 
		out.println(e);  
	}
	
	System.out.println("hostProperties : "+hostProps);////////////////try/////////////////
	System.out.println("usernameProperties : "+usernameProps);////////////////try/////////////////
	System.out.println("passwordProperties : "+passwordProps);////////////////try/////////////////
	System.out.println("databaseProperties : "+databaseProps);////////////////try/////////////////
	
	// connect database
	Connection connect = null;		
	try {
		Class.forName("com.mysql.jdbc.Driver");
	
		connect =  DriverManager.getConnection("jdbc:mysql://" + hostProps  + "/" + databaseProps +
				"?user=" + usernameProps  + "&password=" + passwordProps + "&characterEncoding=tis620");//////"&characterEncoding=tis620" Encoding Thai);
	
		if(connect != null){
			System.out.println("Database Connect Sucesses.");
		} else {
			System.out.println("Database Connect Failed.");	
		}

	} catch (Exception e) {
		out.println(e.getMessage());
		e.printStackTrace();
	}
	
		String flag = request.getParameter("flag");
		int CurriculumIdOLD = Integer.parseInt(request.getParameter("CurriculumId"));
		int CategoryIdOLD = Integer.parseInt(request.getParameter("CategoryId"));
		String categoryName = new String(request.getParameter("categoryName").getBytes("ISO8859_1"),"UTF-8");
	 	int Credit_categoryOLD = Integer.parseInt(request.getParameter("Credit_category"));		
		String OHCE = request.getParameter("OHCE");
	 	String ONEC = request.getParameter("ONEC");	
	 	String EngApp = request.getParameter("EngApp");	
	 	
	 	String tempEngApp = EngApp; // Store real EngApp cannot change.
	 	
	 	int Credit_groupOLD = Integer.parseInt((request.getParameter("Credit_group")));	
	 	int GroupId = Integer.parseInt((request.getParameter("GroupId")));
		String GroupNameOLD = new String(request.getParameter("GroupName").getBytes("ISO8859_1"),"UTF-8");
		
		int temp = 0;
		
		System.out.println("CurID:   "+CurriculumIdOLD);
		System.out.println("CategoryIdOLD:    "+CategoryIdOLD);
		System.out.println("GroupId:   "+GroupId);
		System.out.println("Credit OLD:   "+Credit_groupOLD);		
		System.out.println("GroupName:    "+GroupNameOLD);
		System.out.println("OHCE:    "+OHCE);
		System.out.println("ONEC:    "+ONEC);
		System.out.println("EngApp:    "+EngApp);
		System.out.println("tempEngApp:    "+tempEngApp);
		System.out.println("cchecker:    "+request.getParameter("checker2"));
		
/////////////////////////////////////////////////////////////////////////////////////////////////

/*Find Course in DB*/
List<Course> course3 = new ArrayList<Course>();
List<Group> group3 = new ArrayList<Group>();
List<Category> category3 = new ArrayList<Category>();

try{
	ResultSet rs_cour3 = connect.createStatement().executeQuery("SELECT `course_id`,G.group_id, G.category_id,G.curriculum_id,G.credit,C.group_id,C.curriculum_id,`course_name_th`, `course_name_en`, C.credit, `lecture_hour`,`lab_hour`, `self_learning_hour`, `detail`, `ohce_approved`, `onec_approved`, `curriculum_EngApp`"            
			+ " FROM course C, subject_group G "
			+ " WHERE G.curriculum_id = C.curriculum_id AND G.group_id = C.group_id AND G.curriculum_id ="+CurriculumIdOLD+" AND G.group_id ="+ GroupId +" "
			+ " ORDER BY `course_id`");
	
	while(rs_cour3.next()) {
		Course cour3 = new Course();
		
		cour3.setCourseId(rs_cour3.getString("C.course_id"));
		cour3.setGroupId(rs_cour3.getInt("C.group_id"));
		cour3.setCurriculumId(rs_cour3.getInt("C.curriculum_id"));
		cour3.setCourseNameTH(rs_cour3.getString("course_name_th"));
		cour3.setCourseNameEN(rs_cour3.getString("course_name_en"));
		cour3.setCredit(rs_cour3.getInt("C.credit"));		
		cour3.setLecture(rs_cour3.getInt("lecture_hour"));
		cour3.setLab(rs_cour3.getInt("lab_hour"));
		cour3.setSelfLearn(rs_cour3.getInt("self_learning_hour"));
		cour3.setDetails(rs_cour3.getString("detail"));
		cour3.setOHCE(rs_cour3.getString("ohce_approved"));
		cour3.setONEC(rs_cour3.getString("onec_approved"));
		cour3.setcurriculum_EngApp(rs_cour3.getString("curriculum_EngApp"));
		
		course3.add(cour3);
		
		Group gro3 = new Group();
		gro3.setCategoryId(rs_cour3.getInt("G.category_id"));
		group3.add(gro3);
	}
	
}catch (SQLException e) {
	e.printStackTrace();
}
/////////////////////////////////////////////////////////////////////////////////////////////////

for(int tempi= 0;tempi<course3.size();tempi++){
	temp = temp +course3.get(tempi).getCredit();
	System.out.println("                               c"+course3.size() );
	System.out.println("Total Current Credit:     "+ temp);
}

/////////////////////////////////////////////////////////////////////////////////////////////////
if(request.getParameter("checker2").equals("ADD_elec")){
	
	request.setCharacterEncoding("UTF-8");
	
	String courseId = "ELECTIV";
	
	String courseNameEN = "Free Elective";
	
	String tempcredit = "3";
	
	String credit = "3";
	System.out.println("credit :" + credit);////////////////try////////////////
	
	String lecture = "3";
	System.out.println("lecture :" + lecture);////////////////try////////////////
	
	String lab = "0";
	System.out.println("lab :" + lab);////////////////try////////////////
	
	String selfLearn = "6";
	System.out.println("selfLearn :" + selfLearn);////////////////try////////////////
	
	String details = "";
			
	//Temp
	int tempCredit = temp;			// temp = 0		
	System.out.println("tempCredit:    "+tempCredit);
			
	int Credit_group = Credit_groupOLD;//Maximum Total credit ex=15
	System.out.println("Credit_group :" + Credit_group);////////////////try////////////////
	int Credit_current = tempCredit;//Current Total credit ex=7
	System.out.println("Credit_current :" + Credit_current);////////////////try////////////////
	int Credit_course = Integer.parseInt(credit);//Credit ex:3
	System.out.println("Credit_course :" + Credit_course);////////////////try////////////////
	int Credit_check = Credit_current + Credit_course; // 9+3
	System.out.println("Credit_check :" + Credit_check);////////////////try////////////////
	
	// insert data to database			
	String sql_course = "INSERT INTO  `course`(`course_id`, `group_id`, `curriculum_id`, `course_name_th`, `course_name_en`, `credit`, `lecture_hour`, `lab_hour`, `self_learning_hour`, `detail`, `ohce_approved`, `onec_approved`,`curriculum_EngApp`)"
						+ " VALUES ('"+ courseId +"', "+ GroupId +", "+ CurriculumIdOLD +",' ', '"+ courseNameEN +"', "+ credit +", "+ lecture +", "+ lab +", "+ selfLearn +", '"+ details +"',"+null+", "+ null +",  "+ null +")";
	System.out.println(sql_course);/////////////////////try///////////////////////////////

	temp = Credit_check;
//////////////////////////////////////////
	if(Credit_group < Credit_check){
		temp = tempCredit;
		// If Max Credit < Current + Previous 
		%><script>alert("หน่วยกิตรวมของแผนรายวิชาเกินหน่วยกิตของหลักสูตรค่ะ")</script><%
	}else{		
		try {		
				// insert data into course 
				connect.createStatement().executeUpdate("INSERT INTO  `course`(`course_id`, `group_id`, `curriculum_id`, `course_name_th`, `course_name_en`, `credit`, `lecture_hour`, `lab_hour`, `self_learning_hour`, `detail`, `ohce_approved`, `onec_approved`, `curriculum_EngApp`)"
						+ " VALUES ('"+ courseId +"', "+ GroupId +", "+ CurriculumIdOLD +",' ', '"+ courseNameEN +"', "+ credit +", "+ lecture +", "+ lab +", "+ selfLearn +", '"+ details +"', "+ null +", "+ null +", "+ null +")");
	
				
				/* Log file */
				String log_user = strUser+" add course";
				Log.writeUserFile(log_user);
				Log.writeUserFile(sql_course);
				
				%><script>alert("เพิ่มวิชาเลือกเสรีสำเร็จสำเร็จ")</script><%						
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
/////////////////////////////////////////////////////////////////////////////////////////////////
if(request.getParameter("checker2").equals("ADD")){

		request.setCharacterEncoding("UTF-8");
				
		String checker = request.getParameter("search_box");
		String EngAppSend = null;	
		
		String OHCESend = null;	
		String ONECSend = null;	
		
		String checkedEng = request.getParameter("checkEng").toString();
		System.out.println("OHAYOOOoooooo:    "+checkedEng);
		
		String checkedOHCE = request.getParameter("OHCE").toString();
		System.out.println("OHAYOOOoooooo:    "+checkedOHCE);
		
		String checkedONEC = request.getParameter("ONEC").toString();
		System.out.println("OHAYOOOoooooo:    "+checkedONEC);
				
		if(checkedEng.equals("null")){
			
			EngAppSend = "null" ;
			System.out.println("EngAppSend1 "+EngAppSend);
		
		}else{							
			EngAppSend = "'" + request.getParameter("checkEng") + "'";
			System.out.println("EngAppSend2 "+EngAppSend);
		
		}
		
		if(checkedOHCE.equals("null")){
			
			OHCESend = "null" ;
			System.out.println("OHCESend1 "+OHCESend);
		
		}else{							
			OHCESend = "'" + request.getParameter("OHCE") + "'";
			System.out.println("OHCESend2 "+OHCESend);
		
		}
		if(checkedONEC.equals("null")){
			
			ONECSend = "null" ;
			System.out.println("ONECSend1 "+ONECSend);
		
		}else{							
			ONECSend = "'" + request.getParameter("ONEC") + "'";
			System.out.println("ONECSend2 "+ONECSend);
		
		}
		
		if(checker == "") {
			%><script>alert("กรุณาเลือกรายวิชาก่อนค่ะ");</script><%
		}else{
		
			String course_name = new String(request.getParameter("search_box").getBytes("ISO8859_1"),"UTF-8");// Get info from search box
			System.out.println("course_name :" + course_name);////////////////try////////////////
			
			String[] split = course_name.split(" , ");
			System.out.println("split :" + split.length);////////////////try////////////////
			
		if(split.length == 3){	
				
			
			String courseId = split[0];			
			System.out.println("courseId :" + courseId);////////////////try////////////////
			
			String courseNameEN = split[1];
			System.out.println("courseNameEN :" + courseNameEN);////////////////try////////////////	
			
			String tempcredit = split[2];
			System.out.println("tempcredit :" + tempcredit);////////////////try////////////////					
			String[] split2 = tempcredit.split(" ");
			
			String credit = split2[0];
			System.out.println("credit :" + credit);////////////////try////////////////
			
			String lecture = split2[2];
			System.out.println("lecture :" + lecture);////////////////try////////////////
			
			String lab = split2[3];
			System.out.println("lab :" + lab);////////////////try////////////////
			
			String selfLearn = split2[4];
			System.out.println("selfLearn :" + selfLearn);////////////////try////////////////
			
			String details = "";				
			System.out.println("details :" + details);////////////////try////////////////
			
			//Temp
			int tempCredit = temp;			// temp = 0		
			System.out.println("tempCredit:    "+tempCredit);
					
			int Credit_group = Credit_groupOLD;//Maximum Total credit ex=15
			System.out.println("Credit_group :" + Credit_group);////////////////try////////////////
			int Credit_current = tempCredit;//Current Total credit ex=7
			System.out.println("Credit_current :" + Credit_current);////////////////try////////////////
			int Credit_course = Integer.parseInt(credit);//Credit ex:3
			System.out.println("Credit_course :" + Credit_course);////////////////try////////////////
			int Credit_check = Credit_current + Credit_course; // 9+3
			System.out.println("Credit_check :" + Credit_check);////////////////try////////////////
			
////////////////////////////////////////////////////////////////////////////////
			int checker2 = 0; //0 = not Duplicate, 1 = Duplicate
			for(Course cou : course3 ) {	
				System.out.println("Course DB:  "+cou.getCourseId());
				System.out.println("Course Input:  "+courseId);
			
			if(cou.getCourseId().equals(courseId)){
					System.out.println("Duplicate ID:  "+courseId);
					System.out.println("////////////////////////////////////////////////////");
					checker2 = 1;
				}
			}
			
			if(checker2 == 0){
				// insert data to database			
				String sql_course = "INSERT INTO  `course`(`course_id`, `group_id`, `curriculum_id`, `course_name_th`, `course_name_en`, `credit`, `lecture_hour`, `lab_hour`, `self_learning_hour`, `detail`, `ohce_approved`, `onec_approved`,`curriculum_EngApp`)"
									+ " VALUES ('"+ courseId +"', "+ GroupId +", "+ CurriculumIdOLD +",' ', '"+ courseNameEN +"', "+ credit +", "+ lecture +", "+ lab +", "+ selfLearn +", '"+ details +"',"+ OHCESend +", "+ ONECSend +",  "+ EngAppSend +")";
				System.out.println(sql_course);/////////////////////try///////////////////////////////
			
				temp = Credit_check;
			
				if(Credit_group < Credit_check){
					temp = tempCredit;
					// If Max Credit < Current + Previous 
					%><script>alert("หน่วยกิตรวมของแผนรายวิชาเกินหน่วยกิตของหลักสูตรค่ะ")</script><%
				}else{		
					try {		
							// insert data into course 
							connect.createStatement().executeUpdate("INSERT INTO  `course`(`course_id`, `group_id`, `curriculum_id`, `course_name_th`, `course_name_en`, `credit`, `lecture_hour`, `lab_hour`, `self_learning_hour`, `detail`, `ohce_approved`, `onec_approved`, `curriculum_EngApp`)"
									+ " VALUES ('"+ courseId +"', "+ GroupId +", "+ CurriculumIdOLD +",' ', '"+ courseNameEN +"', "+ credit +", "+ lecture +", "+ lab +", "+ selfLearn +", '"+ details +"', "+ OHCESend +", "+ ONECSend +", "+ EngAppSend +")");
				
							/* Log file */
							String log_user = strUser+" add course";
							Log.writeUserFile(log_user);
							Log.writeUserFile(sql_course);
							
								
							%><script>alert("เพิ่มรายวิชาสำเร็จ")</script><%						
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
			}else{
				System.out.println("/////////////DUPLICATE FILE//////////////");
				%><script>alert("มีรายวิชานี้อยู่แล้วค่ะ")</script><%
			}
		}else{//if(split.length == 5)
			%><script>alert("ชื่อรายวิชาไม่ถูกต้องค่ะ กรุณาเลือกจากรายการที่มีเท่านั้น")</script><%
		}
		}
}		

/*Find Course in DB*/
List<Course> course = new ArrayList<Course>();
List<Group> group = new ArrayList<Group>();
List<Category> category = new ArrayList<Category>();

try{
	ResultSet rs_cour = connect.createStatement().executeQuery("SELECT `course_id`,G.group_id, G.category_id,G.curriculum_id,G.credit,C.group_id,C.curriculum_id,`course_name_th`, `course_name_en`, C.credit, `lecture_hour`,`lab_hour`, `self_learning_hour`, `detail`, `ohce_approved`, `onec_approved`, `curriculum_EngApp`"            
			+ " FROM course C, subject_group G "
			+ " WHERE G.curriculum_id = C.curriculum_id AND G.group_id = C.group_id AND G.curriculum_id ="+CurriculumIdOLD+" AND G.group_id ="+ GroupId +" "
			+ " ORDER BY `course_id`");
	
	while(rs_cour.next()) {
		Course cour = new Course();
		
		cour.setCourseId(rs_cour.getString("C.course_id"));
		cour.setGroupId(rs_cour.getInt("C.group_id"));
		cour.setCurriculumId(rs_cour.getInt("C.curriculum_id"));
		cour.setCourseNameTH(rs_cour.getString("course_name_th"));
		cour.setCourseNameEN(rs_cour.getString("course_name_en"));
		cour.setCredit(rs_cour.getInt("C.credit"));		
		cour.setLecture(rs_cour.getInt("lecture_hour"));
		cour.setLab(rs_cour.getInt("lab_hour"));
		cour.setSelfLearn(rs_cour.getInt("self_learning_hour"));
		cour.setDetails(rs_cour.getString("detail"));
		cour.setOHCE(rs_cour.getString("ohce_approved"));
		cour.setONEC(rs_cour.getString("onec_approved"));
		cour.setcurriculum_EngApp(rs_cour.getString("curriculum_EngApp"));
		
		course.add(cour);
		
		Group gro = new Group();
		gro.setCategoryId(rs_cour.getInt("G.category_id"));
		group.add(gro);
	}
	
}catch (SQLException e) {
	e.printStackTrace();
}


/*Find Course in DB*/
List<Course> course2 = new ArrayList<Course>();

try{
	ResultSet rs_cour2 = connect.createStatement().executeQuery("SELECT `course_id` ,`group_id`,`curriculum_id`"
			+ " FROM course  "
			+ " WHERE curriculum_id="+ CurriculumIdOLD +" AND group_id="+ GroupId );
	
	while(rs_cour2.next()) {
		Course cour2 = new Course();
		
		cour2.setCourseId(rs_cour2.getString("course_id"));
		cour2.setGroupId(rs_cour2.getInt("group_id"));
		cour2.setCurriculumId(rs_cour2.getInt("curriculum_id"));
		
		course2.add(cour2);
		
	}
	
}catch (SQLException e) {
	e.printStackTrace();
}

connect.close();

/////////////////////////////////////////////////////////////////////////////////////////////////

%>
	<div id="page-wrap">
		<div id="inside">
			<table border="0">
				<tr style="font-size:24px">
					<td width="600" height="100" style= "background-color: #273b80;border: 0px ;padding: 0px; 0px;" >
						<div id="header_banner-2"></div>
					</td>
					<td width="680" height="100" style= "background-color: #273b80;border: 0px;padding: 0px; 0px;" >
						<p align="right" ><label><font size="4" color="#FFFFFF">  username : <%=strUser %>&nbsp;&nbsp;</font></label></p>
						<a href="logout.jsp"><p align="right"><label style="cursor: pointer;"><font size="3" color="#ffffff">log out &nbsp;</font></label></p></a>
					</td>							
				</tr>
			</table>
    
				<div id="main-content-2">
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<label><font size="5">กลุ่มวิชา <%=GroupNameOLD %></font></label>
				</div>
				
<!-- //////////////////////////////////////////////////////////////////////////////////// -->

				<div id="main-content-ac" align="center">

					<center>
			<form id="form1" name="form1" method="post" action="curriculum_modified_course.jsp">
					<table>					
					<tr>		
						<td>
							<font size="4">กรุณาใส่รหัสวิชา (ex. egco3)</font>
							<label><font size="5" color="#FF0000">*</font></label>
						</td>					
						<td>
							<input type="text" autocomplete="off" placeholder="ex. egco1 and choose from dropdown lists" name="search_box" id="search_box" style="height: 25px; width: 400px; font-size:medium;" value="" list="namelist" onkeyup="search_name(this.value)" />
								<datalist id="namelist"></datalist>							
						</td>
						<td>
							<input type="radio" name="checkEng" id="checkEng" value="<%=tempEngApp%>"><font size="3">สภาวิศวกรรับรอง</font>
							<input type="radio" name="checkEng" id="checkEng" value="null" checked><font size="3">ไม่มีสภาวิศวกรรับรอง</font>
						</td>
				  		<td>
				  								<input type="hidden" id="CurriculumId" name="CurriculumId" value="<%=CurriculumIdOLD%>" />
												<input type="hidden" id="CategoryId" name="CategoryId" value="<%=CategoryIdOLD%>" />
												<input type="hidden" id="categoryName" name="categoryName" value="<%=categoryName%>" />
												<input type="hidden" id="Credit_category" name="Credit_category" value="<%=Credit_categoryOLD%>" />
												<input type="hidden" id="OHCE" name="OHCE" value="<%=OHCE%>" />
												<input type="hidden" id="ONEC" name="ONEC" value="<%=ONEC%>" />						
												<input type="hidden" id="flag" name="flag" value="completed" />	
												<input type="hidden" id="checker" name="checker" value="none" />
												<input type="hidden" id="Credit_group" name="Credit_group" value="<%=Credit_groupOLD%>" />
												<input type="hidden" id="GroupId" name="GroupId" value="<%=GroupId%>" />
												<input type="hidden" id="GroupName" name="GroupName" value="<%=GroupNameOLD%>" />
												<input type="hidden" id="EngApp" name="EngApp" value="<%=EngApp%>" />	
												<input type="hidden" id="Credit_groupOLD" name="Credit_groupOLD" value="<%=Credit_groupOLD%>" />
													
												<input type="hidden" id="checker2" name="checker2" value="ADD" />	
												
				  				<input type="submit" value="add" name="add" id="add" class="buttonStyle"/>	
				  				<!-- <input type="button" value="add" name="add" id="add" class="buttonStyle"/>	-->
				  		</td>
				  							  		
				  	</tr>	
				  	</form>
				  	
				  	<form id="form2" name="form2" method="post" action="curriculum_modified_course.jsp">	 	
				  	<tr>	
						<td>
							<font size="4">ถ้าต้องการเพิ่ม Free Elective </font><br>
							<font size="4">ให้กดปุ่ม "Add_E" </font>
						</td>						
						
				  		<td>
				  								<input type="hidden" id="CurriculumId" name="CurriculumId" value="<%=CurriculumIdOLD%>" />
												<input type="hidden" id="CategoryId" name="CategoryId" value="<%=CategoryIdOLD%>" />
												<input type="hidden" id="categoryName" name="categoryName" value="<%=categoryName%>" />
												<input type="hidden" id="Credit_category" name="Credit_category" value="<%=Credit_categoryOLD%>" />
												<input type="hidden" id="OHCE" name="OHCE" value="<%=OHCE%>" />
												<input type="hidden" id="ONEC" name="ONEC" value="<%=ONEC%>" />						
												<input type="hidden" id="flag" name="flag" value="completed" />	
												<input type="hidden" id="checker" name="checker" value="none" />
												<input type="hidden" id="Credit_group" name="Credit_group" value="<%=Credit_groupOLD%>" />
												<input type="hidden" id="GroupId" name="GroupId" value="<%=GroupId%>" />
												<input type="hidden" id="GroupName" name="GroupName" value="<%=GroupNameOLD%>" />
												<input type="hidden" id="EngApp" name="EngApp" value="<%=EngApp%>" />	
												<input type="hidden" id="Credit_groupOLD" name="Credit_groupOLD" value="<%=Credit_groupOLD%>" />
													
												<input type="hidden" id="checker2" name="checker2" value="ADD_elec" />	
												
				  				<input type="submit" value="Add_E" name="add2" id="add2" class="buttonStyle"/>
				  				<font size="3"> [ Free Elective 3 ( 3 0 6 ) ] </font>
				  		</td>
				  							  		
				  	</tr>		
				  </form>				  			  	
				  	</table>	
					</center>
						
					
				</div>
				
<!-- //////////////////////////////////////////////////////////////////////////////////// -->
				
				<div id="main-content-ac" align="center">
					<div class="CSSTableGenerator">						
						<table  border="1">
							<tr style="font-size:22px">								
								<center>
									<td>&nbsp;&nbsp;&nbsp;</td>
									<td><center><strong>รหัสวิชา</strong></center></td>
									<td><center><strong>ชื่อวิชา(EN)</strong></center></td>
									<td><center><strong>หน่วยกิต</strong></center></td>
									<td><center><strong>สกอ.รับรอง</strong></center></td>
									<td><center><strong>มหาวิทยาลัยรับรอง</strong></center></td>
									<td><center><strong>สภาวิศวกรรับรอง</strong></center></td>
									<td><center>Delete</center></td>
							</tr>		
				<%// TEST EDIT				    
					int courseCount = 1;
			    	int i=0;
			    	for(Course cou : course ) {			    		
				%>
										<tr style="font-size:18px" id="Curriculum<%=courseCount%>">
										<form id="form<%=courseCount%>" name="form<%=courseCount%>" method="post" action="curriculum_delete_course_modified.jsp">
												
												<input type="hidden" id="CurriculumId" name="CurriculumId" value="<%=CurriculumIdOLD%>" />
												<input type="hidden" id="CategoryId" name="CategoryId" value="<%=CategoryIdOLD%>" />
												<input type="hidden" id="categoryName" name="categoryName" value="<%=categoryName%>" />
												<input type="hidden" id="Credit_category" name="Credit_category" value="<%=Credit_categoryOLD%>" />
												<input type="hidden" id="OHCE" name="OHCE" value="<%=OHCE%>" />
												<input type="hidden" id="ONEC" name="ONEC" value="<%=ONEC%>" />													
												<input type="hidden" id="EngApp" name="EngApp" value="<%=tempEngApp%>" />																			
												<input type="hidden" id="flag" name="flag" value="completed" />	
												<input type="hidden" id="checker" name="checker" value="none" />
												<input type="hidden" id="Credit_group" name="Credit_group" value="<%=Credit_groupOLD%>" />
												<input type="hidden" id="GroupId" name="GroupId" value="<%=GroupId%>" />
												<input type="hidden" id="GroupName" name="GroupName" value="<%=GroupNameOLD%>" />
												
												
												<input type="hidden" id="CourseId" name="CourseId" value="<%=cou.getCourseId()%>" />  
												<td id="courseCount" name="courseCount" align="center">
													<%=courseCount%>
												</td>
												
												<td id="CourseId" name="CourseId" align="center">
													<%=cou.getCourseId()%>
												</td>
												
												<input type="hidden" id="CourseNameTH" name="CourseNameTH" value="<%=cou.getCourseNameTH()%>" />
												
												<input type="hidden" id="CourseNameEN" name="CourseNameEN" value="<%=cou.getCourseNameEN()%>" />  
												<td id="CourseNameEN<%=courseCount%>" name="CourseNameEN<%=courseCount%>" align="center">
													<%=cou.getCourseNameEN()%>
												</td>												
																							
												<input type="hidden" id="CreditNew" name="CreditNew" value="<%=cou.getCredit()%>" /> 
												<td id="CreditNew<%=courseCount%>" name="CreditNew<%=courseCount%>" align="center">
													<center><%=cou.getCredit()%> ( <%=cou.getLecture()%>  <%=cou.getLab()%>  <%=cou.getSelfLearn()%> )</center>
												</td>
													
												<%
													String tempOHCE;
													if(null == cou.getOHCE()){
														tempOHCE = "-";
														System.out.println("tempOHCE "+tempOHCE);
													}else{
														tempOHCE = OHCE;
														System.out.println("tempOHCE "+tempOHCE);
													}
												%>	
																								
												<td id="OHCE<%=courseCount%>" name="OHCE<%=courseCount%>" align="center">
													<%=tempOHCE%>
												</td>
												
												<%
													String tempONEC;
													if(null == cou.getONEC()){
														tempONEC = "-";
														System.out.println("tempONEC "+tempONEC);
													}else{
														tempONEC = ONEC;
														System.out.println("tempONEC "+tempONEC);
													}
												%>
												
												<td id="ONEC<%=courseCount%>" name="ONEC<%=courseCount%>" align="center">
													<%=tempONEC%>
												</td>
												<%
													String tempEng;
													if(null == cou.getcurriculum_EngApp()){
														tempEng = "-";
														System.out.println("tempEng "+tempEng);
													}else{
														tempEng = cou.getcurriculum_EngApp();
														System.out.println("tempEng "+tempEng);
													}
												%>
											
												<td id="EngApp<%=courseCount%>" name="EngApp<%=courseCount%>" align="center">
													<%=tempEng%>
												</td>
												
												<td><center><span title="ลบข้อมูล"><input type="image" src="image/delete_icon.png" height="30px" width="30px" /></span></center></td>
										
											</form>														
										</tr>
				
				<%
						i++;
						courseCount++;

					}
			    
				%>					

								
						</table>
						<br><br>			
							<table>
								<tr style="font-size:20px">
									<td height="50" width = "230">จำนวนหน่วยกิตรวมสูงสุดของกลุ่มวิชา =   <%= Credit_groupOLD%></td>
									<td height="50" width = "230">จำนวนหน่วยกิตรวมของทุกวิชา =   <%= temp%></td>	
									
								</tr>
							</table>
					</div>
				<table>
				<br><br><font size="4" color="red">คำเตือน: ถ้ากดปุ่ม cancel ข้อมูลจะไม่ได้รับการบันทึก !</font><br><br>
					
				<% if(temp == Credit_groupOLD){%>
					
					<form id="form5" name="form5" method="post" action="curriculum_modified_group.jsp" onSubmit="alert('บันทึกข้อมูลวิชาสำเร็จ');">
						<input type="hidden" id="CurriculumId" name="CurriculumId" value="<%=CurriculumIdOLD%>" />
						<input type="hidden" id="CategoryId" name="CategoryId" value="<%=CategoryIdOLD%>" />
						<input type="hidden" id="categoryName" name="categoryName" value="<%=categoryName%>" />
						<input type="hidden" id="Credit_category" name="Credit_category" value="<%=Credit_categoryOLD%>" />
						<input type="hidden" id="OHCE" name="OHCE" value="<%=OHCE%>" />
						<input type="hidden" id="ONEC" name="ONEC" value="<%=ONEC%>" />	
						<input type="hidden" id="EngApp" name="EngApp" value="<%=EngApp%>" />							
						<input type="hidden" id="flag" name="flag" value="completed" />	
						<input type="hidden" id="checker" name="checker" value="none" />
						<input type="hidden" id="Credit_group" name="Credit_group" value="<%=Credit_groupOLD%>" />
						<input type="hidden" id="GroupId" name="GroupId" value="<%=GroupId%>" />
						<input type="hidden" id="GroupName" name="GroupName" value="<%=GroupNameOLD%>" />
						
						<input type="hidden" id="checkerCancel" name="checkerCancel" value="none" />
						<input type="hidden" id="checker2" name="checker2" value="none" />	
					<tr>
								<td height="50" width = "230">										
									<center><input type="submit" value="save" name="save2" class="buttonStyle"/></center>	
								</td>
					</form>	
				<% }%>
					<form id="form5" name="form5" method="post" action="curriculum_modified_group.jsp">
					
						<input type="hidden" id="CurriculumId" name="CurriculumId" value="<%=CurriculumIdOLD%>" />
						<input type="hidden" id="CategoryId" name="CategoryId" value="<%=CategoryIdOLD%>" />
						<input type="hidden" id="categoryName" name="categoryName" value="<%=categoryName%>" />
						<input type="hidden" id="Credit_category" name="Credit_category" value="<%=Credit_categoryOLD%>" />
						<input type="hidden" id="OHCE" name="OHCE" value="<%=OHCE%>" />
						<input type="hidden" id="ONEC" name="ONEC" value="<%=ONEC%>" />
						<input type="hidden" id="EngApp" name="EngApp" value="<%=EngApp%>" />								
						<input type="hidden" id="flag" name="flag" value="completed" />	
						<input type="hidden" id="checker" name="checker" value="none" />
						<input type="hidden" id="Credit_group" name="Credit_group" value="<%=Credit_groupOLD%>" />
						<input type="hidden" id="GroupId" name="GroupId" value="<%=GroupId%>" />
						<input type="hidden" id="GroupName" name="GroupName" value="<%=GroupNameOLD%>" />
					
						<input type="hidden" id="checkerCancel" name="checkerCancel" value="Cancel" />
						<input type="hidden" id="checker2" name="checker2" value="none" />
								<td height="50" width = "230">										
									<center><input type="submit" value="cancel" name="cancel" class="buttonStyle"/></center>	
								</td>
					</tr>
					</form>	
				</table>
				<br><br>
				</div>
				<div style="clear: both;"></div>
					<div id="footer"></div>
		</div>	
					<div style="clear: both;"></div>	
    </div>
</body>
</html>